package com.foreknow.demo4;
/**
* 3. 设计一个类Student，该类会包括姓名，学号，成绩。设计一个方法，按照成绩从高到低的顺序输出姓名，学号和成绩
        * */
public class Student {
    String name;
    int id;
    int sorce;
    public Student(String name,int id,int sorce){
        this.name = name;
        this.id = id;
        this.sorce = sorce;
    }
    public static void Sort(Student[] students){
        for(int i = 1;i < students.length;i++){
            for (int j = 0;j < students.length-i;j++){
                if (students[j].sorce<students[j+1].sorce){
                    Student temp = students[j];
                    students[j] = students[j+1];
                    students[j+1] = temp;
                }
            }
        }
        for (int i=0;i < students.length;i++){
            System.out.println("name:"+students[i].name+"\tid:"+students[i].id+"\tsorce:"+students[i].sorce);
        }
    }
    public static void main(String[] args) {
        Student s1 = new Student("tom",1,90);
        Student s2 = new Student("jimi",2,93);
        Student s3 = new Student("jack",3,88);
        Student s4 = new Student("join",4,98);
        Student[] s = new Student[]{s1,s2,s3,s4};
        Sort(s);

    }
}
